
/**
 * @author LKQ
 * @date 2021/12/27 18:58
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {7286,18704,70773,8224,91675};
        System.out.println(solution.sumFourDivisors(nums));
    }

    public int sumFourDivisors(int[] nums) {
        // 枚举，利用x如果有因数y,那么x/y也是因数。求因数，循环根号n次就行。
        int ans = 0;
        for (int num : nums) {
            // factor_cnt: 因数的个数
            // factor_sum: 因数的和
            int factorCnt = 0, factorSum = 0;
            for (int i = 1; i * i <= num; ++i) {
                if (num % i == 0) {
                    ++factorCnt;
                    factorSum += i;
                    if (i * i != num) {
                        // 判断 i 和 num/i 是否相等，若不相等才能将 num/i 看成新的因数
                        ++factorCnt;
                        factorSum += num / i;
                    }
                }
                if (factorCnt > 4) {
                    break;
                }
            }
            if (factorCnt == 4) {
                ans += factorSum;
            }
        }
        return ans;

    }
}
